﻿//
//
/////////////////////////////////////////////////////////////////////////////

using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

/////////////////////////////////////////////////////////////////////////////
namespace FreeSpaceLibrary.Objects
{
    /////////////////////////////////////////////////////////////////////////
    public class Asteroid
    {
        private Vector2 _position;
        private Rectangle _rectangle;
        private float _radius;
        private float _velocity;
        private Texture2D _objectTexture;

        /////////////////////////////////////////////////////////////////////
        public Asteroid(Vector2 position, ContentManager content, float scaleFactor)
        {
            if (scaleFactor > 0)
            {
                _position = position;
                _objectTexture = ContentLoader.ContentTextures[TextureEnum.AsteroidSmall1];
                _rectangle = new Rectangle(Convert.ToInt32(_position.X), Convert.ToInt32(_position.Y * scaleFactor), Convert.ToInt32(_objectTexture.Width * scaleFactor), Convert.ToInt32(_objectTexture.Height * scaleFactor));
                _radius = (_objectTexture.Width + _objectTexture.Height) / 4f;   
            }
            else
            {
                throw new Exception("The \"scaleFactor\" parameter should be greater then 0.");
            }
        }

        /////////////////////////////////////////////////////////////////////
        public Vector2 Position
        {
            get { return _position; }
            set
            {
                _position = value;
                _position = value;
                _rectangle.X = Convert.ToInt32(value.X);
                _rectangle.Y = Convert.ToInt32(value.Y);
            }
        }

        /////////////////////////////////////////////////////////////////////
        public float Radius
        {
            get { return _radius; }
        }

        /////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Speed. Pixels per second (1000 msec)
        /// </summary>
        public float Velocity
        {
            get { return _velocity; }
            set { _velocity = value; }
        }

        /////////////////////////////////////////////////////////////////////
        public void Draw(SpriteBatch sprite)
        {
            sprite.Begin();
            sprite.Draw(_objectTexture, _rectangle, Color.White);
            sprite.End();
        }
    }
/////////////////////////////////////////////////////////////////////////////
}//FreeSpace.Logic
